<template>
  <div class="">
    <!-- 条件筛选-----查询 -->
    <el-form :inline="true">
      <div style="display: flex; justify-content: space-between;">
        <div>
          <el-form-item>
            <el-input v-model="userid" clearable placeholder="用户ID" style="width: 120px;" />
          </el-form-item>
          <el-form-item>
            <label>币种：</label>
            <el-select v-model="coinid" placeholder="币种">
              <el-option label="全部" :value="0" />
              <el-option v-for="item in Object.keys(coinList)" :label="coinList[item]" :value="Number(item)" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-date-picker v-model="dateTime" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
              start-placeholder="开始日期" end-placeholder="结束日期" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSearch">查询</el-button>
          </el-form-item>
        </div>
        <div />
      </div>

      <el-form-item>
        <div class="flex">
          <div style="font-size: 16px;font-weight: bold;">汇总:</div>
          <div style="margin-left: 20px;">【 充值金额：{{ total.Amount }} 】</div>
        </div>
      </el-form-item>
    </el-form>
    <!-- 列表数据 -->
    <el-table v-loading="listLoading" :data="tableData" border style="width: 100%">
      <el-table-column prop="amount" label="充值金额" align="center" />
      <el-table-column prop="ctime" label="充值时间" align="center">
        <template slot-scope="{row}">
          <div>{{ row.ctime.replace('T', ' ') }}</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="primary"
            @click="$router.push({ name: 'RecordRecharge', query: { ctime: scope.row.ctime } })">明细</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="block " style="padding-top: 20px;">
      <el-pagination background :current-page="pageIndex" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="totalCount" @size-change="idx => { pageSize = idx }"
        @current-change="idx => { pageIndex = idx }" />
    </div>
  </div>
</template>

<script>
import { DayRechargePage } from '@/api/users.js'
import { GetEnum } from "@/api/ctrls.js";
export default {
  name: 'Name',
  data() {
    return {
      userid: '',
      coinid: 0, // 币种ID
      dateTime: [], // 时间查询
      stime: '', // 开始时间 2022-01-01
      etime: '', // 结束时间


      listLoading: false,
      tableData: [],
      totalCount: 0,
      pageIndex: 1,
      pageSize: 10,
      total:{},

      coinList: {}
    }
  },
  computed: {
    // ...mapState({
    //   tradetypeList: state => state.user.enumList["TradeType"]
    // })
  },
  watch: {
    pageIndex(val) {
      console.log(val)
      this.getData()
    },
    pageSize(val) {
      console.log(val)
      this.getData()
    }
  },
  async created() {
    // if (this.$route.query.ctime) {
    //   let tiemIndex = this.$route.query.ctime.indexOf("T");
    //   this.dateTime[1] = this.$route.query.ctime.substring(0, tiemIndex)
    //   this.dateTime[0] = this.$route.query.ctime.substring(0, tiemIndex)
    // }
    this.coinid = Number(this.$route.query.coinid) || 0
  },
  async mounted() {
    this.getData()
    this.GetEnum();
  },
  methods: {
    // 获取枚举
    async GetEnum() {
      const res = await GetEnum();
      this.coinList = res.data['Coin'];
    },
    async onSearch() {
      this.PageIndex = 1
      this.getData()
    },
    // 获取数据
    async getData() {
      this.listLoading = true
      const { list, totalCount,total } = await DayRechargePage({
        userid: this.userid,
        coinid: this.coinid,
        stime: this.dateTime ? this.dateTime[0] : '',
        etime: this.dateTime ? this.dateTime[1] : '',
        pageIndex: this.pageIndex,
        pageSize: this.pageSize
      })
      this.totalCount = totalCount
      this.total = total
      this.tableData = list
      this.listLoading = false
    }
  }
}
</script>

<style lang="scss">
.el-table .warning-row {
  background: oldlace;
}
</style>